//
//  HSYSlideView.m
//  高仿暴走斗图
//
//  Created by key on 16/3/29.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYSlideView.h"

@interface HSYSlideView ()

@property (nonatomic, strong) UILabel *deleteLabel;
@property (nonatomic, strong) UILabel *cancelLabel;

@end

@implementation HSYSlideView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setup];
        [self addGesRecognizer];
    }
    return self;
}

- (void)setup {
    
    self.deleteLabel = [NSObject createLabelWithText:HSYLOCALIZED(@"删除")
                                           textColor:[UIColor blackColor]
                                             bkColor:[[HSYColorHelper shareInstance] deleteColor]
                                                font:HSYFONTSIZE(16)
                                       textAlignment:NSTextAlignmentCenter];
    
    self.deleteLabel.frame = CGRectMake(0, 0, self.viewWidth/2, self.viewHeight);
    [self addSubview:self.deleteLabel];
    
    
    self.cancelLabel = [NSObject createLabelWithText:HSYLOCALIZED(@"取消")
                                           textColor:[UIColor blackColor]
                                             bkColor:[[HSYColorHelper shareInstance] cancelColor]
                                                font:HSYFONTSIZE(16)
                                       textAlignment:NSTextAlignmentCenter];
    self.cancelLabel.frame = CGRectMake(self.deleteLabel.viewMaxX, 0, self.viewWidth/2, self.viewHeight);
    [self addSubview:self.cancelLabel];

}


- (void)addGesRecognizer {
    
    UITapGestureRecognizer *topGesture = [UIView addTapGestureRecognizerWithAction:@selector(topGestureRecognizer:) delegate:self numberOfTouchesRequired:1 numberOfTapsRequired:1];
    [self addGestureRecognizer:topGesture];
}


- (void)topGestureRecognizer:(UITapGestureRecognizer *)topGesture {
    
    CGPoint location = [topGesture locationInView:self];
    if ((location.x >= 0 && location.x < self.viewWidth/2) && (location.y >= 0 && location.y <= self.viewHeight)) {
        
        if (self.didSelectDelete) {
            self.didSelectDelete(kSelectTypeDelete);
        }
    } else if ((location.x >= self.viewWidth/2 && location.x <= self.viewWidth) && (location.y >= 0 && location.y <= self.viewHeight)) {
        
        if (self.didSelectDelete) {
            self.didSelectDelete(kSelectTypeCancel);
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
